home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
autopaint
/
moddir.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
2KB
|
112 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
#include "vect.h"
#include "math.h"
#include "canvas.h"
#define DIRBLEND 0.30
#define MINDELTA 10
float flerp();
extern int winxsize, winysize;
static int origx, origy;
static int lastx, lasty;
static float curdirx, curdiry;
static float startdirx, startdiry;
static int dirsource = DIR_FOLLOW;
static int waiting;
static float curdir;
mousedown(x,y)
int x, y;
{
origx = lastx = x;
origy = lasty = y;
waiting = 1;
}
mousemove(x,y)
int x, y;
{
float delta;
float dx, dy;
int inside;
if(x<0 || x>winxsize || y<0 || y>winysize)
inside = 0;
else
inside = 1;
dx = x-lastx;
dy = y-lasty;
lastx = x;
lasty = y;
delta = fsqrt(dx*dx+dy*dy);
if(delta<1.0) {
if(waiting)
return 0;
else
return inside;
}
if(dirsource == DIR_FOLLOW || dirsource == DIR_FIRST) {
if(waiting) {
dx = x-origx+qrand();
dy = y-origy+qrand();
delta = fsqrt(dx*dx+dy*dy);
if(delta<MINDELTA)
return 0;
curdirx = dx;
curdiry = dy;
setdirection((360.0/(2*M_PI))*fatan2(curdiry,curdirx));
waiting = 0;
}
}
switch(dirsource) {
case DIR_FOLLOW:
dx = dx/delta;
dy = dy/delta;
if (((dx*curdirx)+(dy*curdiry))<0.0) {
dx = -dx;
dy = -dy;
}
curdirx = flerp(curdirx,dx,DIRBLEND);
curdiry = flerp(curdiry,dy,DIRBLEND);
setdirection((360.0/(2*M_PI))*fatan2(curdiry,curdirx));
return inside;
break;
case DIR_FIRST:
return inside;
break;
default:
return inside;
break;
}
}
setdirsource(mode)
int mode;
{
dirsource = mode;
}
setdirection(dir)
float dir;
{
curdir = dir;
setangle(curdir+30.0*qrand());
}